package com.zwps.biz.domain.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zwps.biz.api.model.dto.dsmspgpzwl.PaginatedResult;
import com.zwps.biz.api.model.vo.dsmspgpzwl.DsmSectionVO;
import com.zwps.biz.api.model.vo.dsmspgpzwl.DsmSpgPzwDateVO;
import com.zwps.biz.api.model.vo.pubsectionall.PubSectionAllVO;
import com.zwps.biz.api.model.vo.pubsectionall.PubSectionAllVOS;
import com.zwps.biz.api.model.vo.ststbprp.StStbprpBVO;
import com.zwps.biz.dal.db.dao.PubPointAllDAO;
import com.zwps.biz.dal.db.object.PubSectionAllDO;
import com.zwps.biz.dal.db.object.StStbprpBDO;
import com.zwps.biz.domain.converter.PubSectionAllConverter;
import com.zwps.biz.domain.converter.StStbprpBConverter;
import com.zwps.biz.domain.service.PubSectionAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zwps.biz.dal.db.dao.PubSectionAllDAO;

import java.util.*;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class PubSectionAllServiceImpl extends ServiceImpl<PubSectionAllDAO, PubSectionAllDO> implements PubSectionAllService {
    @Autowired
    private PubSectionAllDAO pubSectionAllDAO;
    @Autowired
    private PubPointAllDAO pubPointAllDAO;
    @Override
    public List<PubSectionAllVOS> getData() {
        List<PubSectionAllVOS> list = pubSectionAllDAO.getLists();
        list.forEach(item -> {
            if (item.getChildren() == null) {
                item.setChildren(new ArrayList<>());
            }
            item.getChildren().addAll(pubSectionAllDAO.getSccd(item.getHycncd()));
            if (item.getChildren().isEmpty()){
                PubSectionAllVO vo = new PubSectionAllVO();
                List<String> list1 = pubPointAllDAO.querryOtherSection(item.getHycncd());
                vo.setCd( list1);
                item.getChildren().add(vo) ;
            }else {
              item.getChildren().forEach(item1 -> {
                  if (item1.getCd() == null) {
                      item1.setCd(new ArrayList<>());
                  }
                  List<DsmSectionVO> sectionVOS = pubPointAllDAO.querrySection(String.valueOf(item1.getSccd()));
                  for (DsmSectionVO section : sectionVOS) {
                      item1.getCd().addAll(
                              Arrays.stream(section.getPtcds().split(","))
                                      .map(String::trim)
                                      .collect(Collectors.toList())
                      );
                  }
              });
            }
        });
        return list;

    }
}




